using System;
using System.Collections.Generic;
using System.Net.Mail;
using JetBrains.Annotations;
using Kaleida.ServiceMonitor.Framework;
using Kaleida.ServiceMonitor.Model.Runtime;

namespace Kaleida.ServiceMonitor.Model.ScriptDirectives
{
    public class EmailOnThresholdChangeDirective : IScriptDirective
    {
        private readonly IList<MailAddress> recipientEmails;

        public EmailOnThresholdChangeDirective([NotNull] string recipients)
        {
            if (recipients == null) throw new ArgumentNullException("recipients");

			recipientEmails = recipients.ToMailAddressList();
        }

        public CompiledNode Apply([NotNull] CompiledScriptModule module)
        {
            module.EmailOnThresholdChangeRecipients = recipientEmails;
            return new CompiledNode(module);
        }
    }
}